Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Vue.js 3 Custom Checkbox issue. Add three checkboxes in one template, all the "action" is only on the first checkbox
<template>
    <div>
         <span v-html="title" />
        <input @change.preventDefault="change"  type="checkbox" id="check" v-model="checked" class="toggle" />
        <label for="check">&ensp;{{ status }}</label>
    </div>

</template>

<script lang="ts" setup>
        import { ref, reactive } from 'vue'

    interface Props {
        title?: String | Number | null;
        required?: boolean;
        checked?: boolean;
        }

    const props = withDefaults(defineProps<Props>(), {
            title: null,
            required: false,
            checked: undefined,
           
        });

        const emit = defineEmits([ "onChange"]);
        const checked = ref(props.checked)
        const status = ref(checked.value ? 'true' : 'false')
        const value = reactive({ })

        const change = () => {
            status.value = checked.value ? 'true' : 'false';
            emit("onChange", checked.value)
         }

</script>

So I am using this custom checkbox component, and have three of them on the same page. When I click the first one, the checkbox action and label change is fine, but when I check the second or third checkbox, the checkbox action and label change is shown on the first one rather than the one that was checked.

How can I make this component more functional that each checkbox performs its own action, independent of the others?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!